import allure
from airtest.core.api import *

from common.airtest.airtest_base import AirtestBase, exists_1
from common.log.log import log
from config.conf import BASE_DIR
from po.jinhua.applets_po.my.redemption_details_page import RedemptionDetailsPage


class ExchangeRecordPage:
    """
    个人中心-兑换优惠券页面
    """

    @allure.step('兑换优惠券页，查看兑换记录')
    def view_records(self):
        """查看兑换记录"""
        try:
            log.info('兑换优惠券页，查看兑换记录')
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/兑换优惠券页/兑换记录.png")
        except Exception as e:
            log.error(f'兑换优惠券页，查看兑换记录过程中出现异常为：{e}')
            raise e

    @allure.step('兑换优惠券页，点击（积分）进入兑换优惠券详情页')
    def go_to_the_redemption_details_page(self):
        """兑换优惠券页，点击（积分）进入兑换优惠券详情页"""
        try:
            log.info('兑换优惠券页，点击（积分）进入兑换优惠券详情页')
            element_1 = BASE_DIR + r"/element_picture/我的/兑换优惠券页/积分.png"
            if exists_1(element_1):
                AirtestBase().click_5(element_1)
                return RedemptionDetailsPage()
            else:
                log.info('兑换优惠券列表，暂无数据哦！！')
        except Exception as e:
            log.error(f'兑换优惠券页，点击（积分）进入兑换优惠券详情页过程中出现异常为：{e}')
            raise e
